﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using ThietBiSo.Controllers;
using ThietBiSo.Models;

namespace ThietBiSo
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        private MThongKe mtk = new MThongKe();
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
           "xd", // Route name
           "xd/{id}", // URL with parameters              
           new { controller = "xd", action = "xd", id = UrlParameter.Optional } // Parameter defaults
       );  



            routes.MapRoute(
            "Index", // Route name
            "danhmucsp/{id}", // URL with parameters              
            new { controller = "danhmucsp", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
            routes.MapRoute(
                       "Index1", // Route name
                       "dichvu/{id}", // URL with parameters              
                       new { controller = "dichvu", action = "Index1", id = UrlParameter.Optional } // Parameter defaults
                   );
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "home", action = "index", id = UrlParameter.Optional } // Parameter defaults
            );

         
          

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            Application["HomNay"] = 0;
            Application["HomQua"] = 0;
            Application["TuanNay"] = 0;
            Application["TuanTruoc"] = 0;
            Application["ThangNay"] = 0;
            Application["ThangTruoc"] = 0;
            Application["TatCa"] = 0;
            Application["visitors_online"] = 0;
        }
        protected void Session_Start()
        {
            //Session.Timeout = 150;
            Application.Lock();
            Application["visitors_online"] = Convert.ToInt32(Application["visitors_online"]) + 1;
            Application.UnLock();
            try
            {               
               
                var tk = mtk.FindAll();
                foreach (var item in tk)
                {
                    Application["HomNay"] = item.HomNay;
                    Application["HomQua"] = item.HomQua;
                    Application["TuanNay"] = item.ThangNay;
                    Application["TuanTruoc"] = item.TuanTruoc;
                    Application["ThangNay"] = item.ThangNay;
                    Application["ThangTruoc"] = item.ThangTruoc;
                    Application["TatCa"] = item.TatCa;
                }
            }
            catch { }
        }
        void Session_End(object sender, EventArgs e)
        {

            Application.Lock();
            Application["visitors_online"] = Convert.ToUInt32(Application["visitors_online"]) - 1;
            Application.UnLock();

        }
    }
}